#ifndef __BUFFER_H__
#define __BUFFER_H__

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "xdebug.h"
#include "common.h"

typedef struct buffer
{
    unsigned char   *data;
    int             max;  // 缓冲区大小
    int             pos;  // 缓冲区中的当前位置
    int             len;  // 缓冲区中的有效大小
    char            filename[256];
    FILE            *file;
    int             filesize;
    char            eob;
    int             mode; // 模式,0为读,1为写, 3为追加写
}BUFFER;

BUFFER*     buf_new (int, const char*, int);
void        buf_delete (BUFFER*);
void        buf_clear (BUFFER*);
void        buf_reset (BUFFER*);
int         buf_readn (BUFFER*, int, char**);
int         buf_writen (BUFFER*, char*, int);
int         buf_read_file (BUFFER *buf);
int         buf_write_file (BUFFER *buf);
int         buf_file_pos (BUFFER *buf);
int         buf_getline (BUFFER*, char**, int*); 
int         buf_getfield (BUFFER*, char**, int*);
int         buf_ungetline(BUFFER*, char**, int*);
int         buf_ungetfield(BUFFER*, char**, int*);
char*       buf_find (BUFFER*, char *);
void        buf_skip(BUFFER*, int);
void        buf_skips(BUFFER*, char*, int);

#endif


